<?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

require_once 'KBCommentView_helper.php';


class KBCommentView_list extends AppView
{
	
	var $tmpl = 'list.html';

	
	function execute(&$obj, &$manager) {

		$tpl = &new tplTemplatez($this->template_dir . $this->tmpl);
	
	
		//BB CODE
		$parser = &KBCommentView_helper::getBBCodeObj();
	
		// header generate
		$bp =& $this->pageByPage($manager->limit, $manager->getRecordsSql());
		$tpl->tplAssign('header', $this->commonHeaderList($bp->nav, false, false));
		
		// sort generate
		$sort = &$this->getSort();		
		$manager->setSqlParamsOrder($sort->getSql());
		
		// get records		
		$rows =& $this->stripVars($manager->getRecords($bp->limit, $bp->offset));
		
		// list records
		foreach($rows as $row) {
			
			$obj->set($row);
			$obj->set('comment', $parser->qparse($obj->get('comment')));
			
			$tpl->tplAssign('title', $row['title']);
			$tpl->tplAssign('formated_date', $this->getFormatedDate($row['date_posted']));
			
			$tpl->tplAssign($this->getViewListVars($obj->get('id'), $obj->get('active')));
			
			$tpl->tplParse(array_merge($obj->get(), $this->msg), 'row');
		}
		
		$tpl->tplAssign($this->msg);
		$tpl->tplAssign($sort->toHtml());
		
		$tpl->tplParse();
		return $tpl->tplPrint(1);
	}

	
	function &getSort() {
		//$sort = new TwoWaySort();
		$sort = new OneWaySort($_GET);
		$sort->default_order = 2;
		$sort->setTitleMsg('asc',  $this->msg['sort_asc_msg']);
		$sort->setTitleMsg('desc', $this->msg['sort_desc_msg']);
		$sort->setSortItem('comment_msg',  'comment', 'c.comment', $this->msg['comment_msg']);
		$sort->setSortItem('entry_title_msg', 'title', 'c.entry_id', $this->msg['entry_title_msg']);
		$sort->setSortItem('date_posted_msg', 'date', 'c.date_posted', $this->msg['date_posted_msg'], 2);
		$sort->setSortItem('status_msg','status', 'active', $this->msg['status_msg']);
		
		//$sort->getSql();
		//$sort->toHtml()
		return $sort;
	}
}
?>
